/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ngramassigment;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;

/**
 *
 * @author Tran
 */
public class Utils {

    public static void storeMaxValue(String properties,int value) {
        Properties prop = new Properties();
        OutputStream output = null;

        try {
            output = new FileOutputStream(Config.FILE_PROPERTIES);

            // set the properties value
            prop.setProperty(properties, ""+value);            

            // save properties to project root folder
            prop.store(output, null);

        } catch (IOException io) {
            //io.printStackTrace();
        } finally {
            if (output != null) {
                try {
                    output.close();
                } catch (IOException e) {
                    //e.printStackTrace();
                }
            }

        }
    }
    
    public static int getMaxValue(String propKey) throws IOException{
        Properties prop = new Properties();
	InputStream input = null;
        int res = 0;
 
	try {
 
		input = new FileInputStream(Config.FILE_PROPERTIES);
 
		// load a properties file
		prop.load(input);
 
		// get the property value and print it out
		res  = Integer.parseInt(prop.getProperty(propKey, "0"));
		
                
	
	} finally {
		if (input != null) {
			
			input.close();	
                         return res;
		}
	}
       return res;
    }
}
